﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using Eacademy.Domain.Abstractions;
using Eacademy.Domain.Models;
using Eacademy.Library.Membership;
using Eacademy.Library.Actions;

namespace Eacademy.Areas.Student.Controllers
{
    [ProfileControllerFilter]
    public class HomeController : Controller
    {
        private ISubjectRepository _subjectRepository;
        private IMentorRepository _mentorRepository;
        private IQuizRepository _quizRepository;
        private IStudentRepository _studentRepository;

        public HomeController(IStudentRepository studentRepository,ISubjectRepository subjectRepository, IMentorRepository mentorRepository, IQuizRepository quizRepository)
        {
            _subjectRepository = subjectRepository;
            _mentorRepository = mentorRepository;
            _quizRepository = quizRepository;
            _studentRepository = studentRepository;
        }
        //
        // GET: /Student/Student/

        private static CustomMembershipProvider Provider
        {
            get
            {
                return (CustomMembershipProvider)Membership.Provider;
            }
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Enroll()
        {
            SubjectListViewModel subjectList = new SubjectListViewModel();
            subjectList.SubjectList = _subjectRepository.GetSubjectsForStudent((int)Provider.User.UserId);
            foreach (SubjectCompactViewModel subject in subjectList.SubjectList)
            {
                subject.MentorList = _mentorRepository.GetMentorsBySubject(subject.SubjectId);
            }
            return View(subjectList);
        }

        [HttpPost]
        public ActionResult EnrollSubject(int id, int mentorId)
        {
            if (_subjectRepository.SetSubjectEnrolled(id, mentorId, (int)Provider.User.UserId))
            {
                this.FlashDone("The request has been sent. Please wait for the confirmation");
            }
            else
            {
                this.FlashError("Request sending failed");
            }
            return Content("OK");

        }

        public ActionResult Gradebook()
        {
            GradeBookViewModel gradeBookViewModel = new GradeBookViewModel();
            gradeBookViewModel.SubjectGradeViewModels = _quizRepository.GetGradeBookByUserId((int)Provider.User.UserId);
            return View(gradeBookViewModel);
        }

        public ActionResult Messages()
        {
            return View();
        }
        public ActionResult Glossary()
        {
            return View();
        }
        public ActionResult MessageDetails()
        {
            return View();
        }

    }
}
